package com.fzshang.shopping.api.controller;


import com.fzshang.shopping.commen.bean.WheelPlanting;
import com.fzshang.shopping.commen.bean.layuiBean.ResultPage;
import com.fzshang.shopping.commen.bean.layuiBean.VoPage;
import com.fzshang.shopping.commen.controller.BaseController;
import com.fzshang.shopping.commen.entity.ApiResult;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-07
 */
@Controller
@RequestMapping("admin/wheelPlanting")
public class WheelPlantingController extends BaseController {

    @RequestMapping(value = "wheelPlanting.html")
    public String wheelPlanting(){
        return "admin/wheelPlanting/wheelPlanting";
    }

    @RequestMapping(value = "wheelPlanting_add.html")
    public String wheelPlanting_add(){
        return "admin/wheelPlanting/wheelPlanting_add";
    }

    @RequestMapping(value = "wheelPlanting_edit.html")
    public String wheelPlanting_edit(Model model,Long id){
        WheelPlanting wheelPlanting = wheelPlantingService.getById(id);
        model.addAttribute("wheelPlanting",wheelPlanting);
        return "admin/wheelPlanting/wheelPlanting_edit";
    }

    /**
     * @param voPage
     * @return 后台查询
     */
    @RequestMapping(value = "selectMyPage",method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<WheelPlanting> selectMyPage(VoPage voPage){
        return wheelPlantingService.selectMyPage(voPage);
    }

    /**
     * @param wheelPlanting
     * @return 添加
     */
    @RequestMapping(value = "saveOrUpdateById")
    @ResponseBody
    public ApiResult saveOrUpdateById(@RequestBody WheelPlanting wheelPlanting){
        wheelPlanting.setCreateTime(System.currentTimeMillis());
        if(wheelPlantingService.saveOrUpdate(wheelPlanting)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

    /**
     * @param id
     * @return 添加
     */
    @RequestMapping(value = "deleteById")
    @ResponseBody
    public ApiResult deleteById(Long id){
        if(wheelPlantingService.removeById(id)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

}
